/*
 * SwingGraphics.h  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef SWINGGRAPHICS_H
#define SWINGGRAPHICS_H

#include "Cute4jSwing.h"

// SwingGraphics Class. --------------------------------------------------------

/*!
 * \brief Extended QPainter.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT SwingGraphics : public QPainter
{
public:
  SwingGraphics(QPaintDevice *device);
  SwingGraphics(QPaintDevice *device, jint x, jint y, jint width, jint height);
public:
  jobject getColor();
  void setColor(jint argb);
  jobject getFont();
  void setFont(jobject font);
  void setLinearGradient(jint x1, jint y1, jint argb1, jint x2, jint y2,
                         jint argb2, jboolean cyclic);
  void setTextureGradient(QPixmap *image);
  void setBasicStroke(jfloat width, jint cap, jint join, jfloat miterLimit,
                      jfloatArray dash, jfloat dashPhase);
  void push();
  void pop();
  void drawImage(jbyteArray imageData, jint length, jint x, jint y);
  void fillRect(jint x, jint y, jint w, jint h);
  void fillOval(jint x, jint y, jint w, jint h);
public:
  inline static bool canPaint(JNIEnv *env, jlong graphicsPointer);
private:
  static const Qt::PenCapStyle PEN_CAP_STYLE[];
  static const Qt::PenJoinStyle PEN_JOIN_STYLE[];
};

// SwingGraphics :: Public Static Inline Member Function. ----------------------

/*!
 * \brief Tests if specifed graphics can paint.
 *
 * \param env the JNIEnv pointer
 * \param graphicsPointer the graphics pointer
 *
 * \return \c true if graphics object can paint
 */
inline bool SwingGraphics::canPaint(JNIEnv *env, jlong graphicsPointer)
{
  return (graphicsPointer && JNISwingWrapper::isSwingThread(env));
}

// Macro Definitions. ----------------------------------------------------------

// TODO: make upper case
#define swingGraphics (reinterpret_cast<SwingGraphics *>(graphicsPointer))
#define qPainterPath (reinterpret_cast<QPainterPath *>(painterPathPointer))
#define qPaintDevice (reinterpret_cast<QPaintDevice *>(paintDevicePointer))

#endif // SWINGGRAPHICS_H
